package com.meida.module.bus.provider.handler;

import cn.hutool.core.util.ObjectUtil;
import com.meida.common.base.entity.EntityMap;
import com.meida.common.mybatis.interceptor.PageInterceptor;
import com.meida.common.mybatis.model.PageParams;
import com.meida.common.mybatis.query.CriteriaQuery;
import com.meida.module.bus.client.entity.VipType;
import com.meida.module.bus.client.entity.VipUser;
import com.meida.module.pay.client.entity.PayBalance;
import com.meida.module.user.client.entity.AppUser;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.stereotype.Component;


/***
 * @description: 会员列表
 * @date: 2022年-06月-30日  15:06:49
 * @author lidd
 */
@Component("appUserPageHandler")
public class AppUserPageHandler implements PageInterceptor<AppUser> {
    private static final Logger log = LogManager.getLogger(AppUserPageHandler.class);


    public AppUserPageHandler() {
    }


    @Override
    public void prepare(CriteriaQuery cq, PageParams pageParams, EntityMap params) {
        cq.select(AppUser.class, "*");
        cq.select(VipType.class, "vipName", "vipCode", "vipTypeId");
        cq.select("vipUser.groupNum");
        cq.select(PayBalance.class, "amount", "bindAmount", "commAmount");
        cq.createJoin(VipUser.class).setJoinAlias("vipUser").setMainField("userId").setJoinField("userId");
        cq.createJoin(VipType.class).setMainAlias("vipUser").setMainField("vipTypeId");
        cq.createJoin(PayBalance.class).setMainField("userId").setJoinField("userId");
        cq.like(ObjectUtil.isNotNull(params.get("fullName")), "user.fullName", params.get("fullName"));
        cq.like(ObjectUtil.isNotNull(params.get("idCard")), "user.idCard", params.get("idCard"));
        cq.like(ObjectUtil.isNotNull(params.get("nickName")), "user.nickName", params.get("nickName"));
        cq.like(ObjectUtil.isNotNull(params.get("wechatNo")), "user.wechatNo", params.get("wechatNo"));
        cq.like(ObjectUtil.isNotNull(params.get("shareCode")), "user.shareCode", params.get("shareCode"));
        cq.like(ObjectUtil.isNotNull(params.get("mobile")), "user.mobile", params.get("mobile"));
        cq.like(ObjectUtil.isNotNull(params.get("inviterId")), "user.inviterId", params.get("inviterId"));
        cq.eq(ObjectUtil.isNotNull(params.get("status")), "user.status", params.get("status"));
        cq.like(ObjectUtil.isNotNull(params.get("userId")), "user.userId", params.get("userId"));
        cq.isNull(ObjectUtil.isNotNull(params.get("vipCode")) && "0".equals(params.get("vipCode")), "type.vipCode");
        cq.eq(ObjectUtil.isNotNull(params.get("vipCode")) && !"0".equals(params.get("vipCode")), "type.vipCode", params.get("vipCode"));
        cq.ge(ObjectUtil.isNotEmpty(params.get("beginDate")), "user.createTime", params.get("beginDate"));
        cq.le(ObjectUtil.isNotEmpty(params.get("endDate")), "user.createTime", params.get("endDate"));
    }


}
